import React,{Component}from 'react'
import {Descriptions} from 'antd';
import {Button,Modal,Form,Input,message} from 'antd';
import http from '../../api/http';
import AES from '../../api/secret'
class Admininfo  extends Component{
    constructor(props){
        super(props)
        this.state = {visible:false}
    }
    // 打开弹框
    updatepass(){this.setState({visible:true})}
    // 关闭弹框
    handleCancel= () =>{this.setState({visible: false,});};
    handleOk = ()=>{
        this.props.form.validateFields((err, values) => {
            var that = this
            if (!err){
                http.put('backstage/updateAdminUserPasswd/'+AES.Encrypt(values.newPasswd)+'/'+AES.Encrypt(values.oldPasswd),' ','ADMINUSER').then(res =>{
                    if(res.code === 0){
                        that.setState({visible: false});
                        message.success('修改成功', 10);
                    }else{
                        message.error(res.data +'  ，错误码：'+res.code);
                    }
                })
            }
        });
    }
    render(){
        var user = JSON.parse(localStorage.getItem('userinfo'))||'';
        const { getFieldDecorator } = this.props.form;
        return(
            <div>
                <Descriptions title="管理员信息">
                    <Descriptions.Item label="用户昵称">{user.nickName}</Descriptions.Item>
                    <Descriptions.Item label="Telephone">{user.nickName}</Descriptions.Item>
                    <Descriptions.Item label="用户名称">{user.name}</Descriptions.Item>
                    <Descriptions.Item label="邮箱地址">{user.email}</Descriptions.Item>
                </Descriptions>
                <div onClick={this.updatepass.bind(this)}><Button>修改密码</Button></div>
                <div>
                    <Modal title='密码修改' visible={this.state.visible} onOk={this.handleOk.bind(this)} onCancel={this.handleCancel} width={600} cancelText='关闭' okText='提交'>
                        <Form onSubmit={this.handleOk.bind(this)} className="login-form form bases-form">
                            <Form.Item>
                                {getFieldDecorator('oldPasswd',{rules: [{ required: true, message: '请输入密码'}],})(
                                <Input type='password' size='large' placeholder="密码"/>,)}
                            </Form.Item>
                            <Form.Item>
                                {getFieldDecorator('newPasswd',{rules: [{ required: true, message: '请输入新密码'}],})(
                                <Input type='password' size='large' placeholder="新密码" />,)}
                            </Form.Item>
                        </Form>
                    </Modal>
                </div>
            </div>
        )
    }
}
const infoForm = Form.create({ name: 'normal_auth' })(Admininfo);
export default infoForm